#ifndef MYPLAYER_H
#define MYPLAYER_H

#include <QObject>

class MYPlayer : public QObject
{
    Q_OBJECT

    Q_PROPERTY(int demoNum READ demoNum WRITE setDemoNum NOTIFY demoNumChanged)

    Q_PROPERTY(int testNum READ testNum WRITE setTestNum NOTIFY testNumChanged)

    Q_PROPERTY(double posNum READ posNum WRITE setPosNum NOTIFY posNumChanged)

    Q_PROPERTY(QObject* source READ source WRITE setSource NOTIFY sourceChanged)

    Q_PROPERTY(bool isPlay READ isPlay WRITE setIsPlay NOTIFY isPlayingChanged)

    Q_PROPERTY(bool openSuccess READ openSuccess WRITE setOpenSuccess NOTIFY openSuccessChanged)

    Q_PROPERTY(QString backGround READ backGround WRITE setBackGround NOTIFY backGroundChanged)

    Q_PROPERTY(QString backGroundChoose READ backGroundChoose WRITE setBackGround NOTIFY backGroundChooseChanged)

    Q_PROPERTY(QString videoPath READ videoPath WRITE setVideoPath NOTIFY videoPathChanged)

    Q_PROPERTY(QString subTitlePath READ subTitlePath WRITE setSubTitlePath NOTIFY subTitlePathChanged)

    Q_PROPERTY(QString subTitleText READ subTitleText WRITE setSubTitleText NOTIFY subTitleTextChanged)

    Q_PROPERTY(QString endTime READ endTime WRITE setEndTime NOTIFY endTimeChanged)

    Q_PROPERTY(QString currentTime READ currentTime WRITE setCurrentTime NOTIFY currentTimeChanged)


public:
    MYPlayer();
    ~MYPlayer();

    // QML invokable functions
    // 可在qml直接调用
    Q_INVOKABLE void testFunc();

    // 打开线程，传输文件路径
    Q_INVOKABLE void urlPass(QString url);
    // 播放进度条
    Q_INVOKABLE void posFind(double value);
    // 暂停/播放
    Q_INVOKABLE void playOrPause();
    // 快进
    Q_INVOKABLE void goOn();
    // 快退
    Q_INVOKABLE void goBack();
    // 改变背景
    Q_INVOKABLE void changeBackground(QString url);
    // 更改视频
    Q_INVOKABLE void changeVideoPath(QString url);
    // 更改字幕文件
    Q_INVOKABLE void changeSubtitlePath(QString url);
    // 调音量
    Q_INVOKABLE void setVolume(double newVolume);
    // 停止
    Q_INVOKABLE void setStop();
    // 加载字幕
    Q_INVOKABLE void loadSubtitle(QString url);

    // 定时器 滑动条显示
    void timerEvent(QTimerEvent *e);


    // For QML property(-ies)
    // 上面Q_PROPERTY对应的方法实现
    int demoNum() const;
    void setDemoNum(int newValue);

    int testNum() const;
    void setTestNum(int newValue);

    double posNum() const;
    void setPosNum(double newValue);

    QObject *source() const;
    void setSource(QObject *source);

    bool isPlay() const;
    void setIsPlay(bool isPlaying);

    bool openSuccess() const;
    void setOpenSuccess(bool openSuccess);
    //背景图片路径
    QString backGround() const;
    void setBackGround(QString url);
    //选择背景路径
    QString backGroundChoose() const;
    //选择视频路径
    QString videoPath() const;
    void setVideoPath(QString url);
    //选择字幕路径
    QString subTitlePath() const;
    void setSubTitlePath(QString url);
    //字幕文本
    QString subTitleText() const;
    void setSubTitleText(QString text);

    // 视频时长
    QString endTime() const;
    void setEndTime(QString value);

    // 当前播放位置
    QString currentTime() const;
    void setCurrentTime(QString value);

signals:
    void demoNumChanged(int newValue);
    void testNumChanged(int newValue);
    void posNumChanged(double newValue);
    void sourceChanged(QObject *object);
    void isPlayingChanged(bool isPlaying);
    void openSuccessChanged(bool openSuccess);
    void backGroundChanged(QString url);
    void backGroundChooseChanged(QString url);
    void videoPathChanged(QString url);
    void subTitlePathChanged(QString url);
    void subTitleTextChanged(QString text);

    void endTimeChanged(QString newValue);
    void currentTimeChanged(QString newValue);

private:
    int m_DemoNum{ 0 };
    int m_TestNum{ 0 };
    double m_PosNum{ 0.0 };
    QObject* m_Source{nullptr};
    bool m_IsPlaying{false};
    bool m_OpenSuccess{false};
    QString m_strBackgroundPath{""};
    QString m_strBackGroundChoosePath{""};
    QString m_strVideoPath{""};
    QString m_strTheVideoPath{""};
    QString m_strSubTitlePath{""};
    QString m_strSubTitleText{""};
    long long m_totalMs {0};
    QString m_endTime{""};
    QString m_currentTime{""};
};

#endif // MYPLAYER_H
